//
//  HMTabBar.m
//  OC新浪微博
//
//  Created by wyman on 16/4/9.
//  Copyright © 2016年 wyman. All rights reserved.
//

#import "HMTabBar.h"

@implementation HMTabBar
#define count 5
//-(instancetype)initWithFrame:(CGRect)frame
//{
//    if (self = [super initWithFrame:frame]) {
//        //添加按钮
//        [self addTabItem];
//    }
//    
//    return self;
//}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    [self addTabItem];


}

-(void)addTabItem
{
    CGFloat width = self.frame.size.width / count;
    
    CGRect newFrame = CGRectMake(0, 0, width, self.frame.size.height);
    

    NSInteger index = 0;
    for (UIView *view in self.subviews) {
        
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            view.frame = CGRectOffset(newFrame, width*index, 0);
             index += index == 1 ? 2 : 1;
            
        }
}
    

    //添加加号按钮
    UIButton *addBtn = [[UIButton alloc]init];
    [addBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:normal] ;
    
    [addBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:normal];
    [self addSubview:addBtn];
    addBtn.frame = CGRectMake(width*2, 0, width, self.frame.size.height);

}
@end
